package com.corticon.dialogs.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 * ResponseEntry entity.
 * 
 * @author Yanglifan
 */
@Entity
@Table(name = "q_responseentry")
public class ResponseEntry extends AuditableEntity implements Serializable, Comparable {

    private Long responseEntryId;
    private String id;
    private String label;
    private Long sequence;
    private String value;
    private ResponseType responseType;

    public ResponseEntry() {
    }

    public ResponseEntry(String id, String label, Long sequence, String value,
                         ResponseType responseType) {
        this.id = id;
        this.label = label;
        this.sequence = sequence;
        this.value = value;
        this.responseType = responseType;
    }

    @Id
    @SequenceGenerator(name = "q_responseentry_id_seq",
            sequenceName = "q_responseentry_id_seq",
            allocationSize = 1, initialValue = 1)
    // Set allocationSize and initialValue
    // to let sequence increment following DB.)
    @GeneratedValue(strategy = GenerationType.AUTO,
            generator = "q_responseentry_id_seq")
    @Column(name = "q_responseentry_id", columnDefinition = "integer")
    public Long getResponseEntryId() {
        return this.responseEntryId;
    }

    public void setResponseEntryId(Long responseEntryId) {
        this.responseEntryId = responseEntryId;
    }

    @Column(name = "id")
    public String getId() {
        return this.id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Column(name = "label")
    public String getLabel() {
        return this.label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    @Column(name = "sequence")
    public Long getSequence() {
        return this.sequence;
    }

    public void setSequence(Long sequence) {
        this.sequence = sequence;
    }

    @Column(name = "value")
    public String getValue() {
        return this.value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "resptypeassoc_resptype_id_oid")
    public ResponseType getResponseType() {
        return this.responseType;
    }

    public void setResponseType(ResponseType responseType) {
        this.responseType = responseType;
    }

    @Override
    public int compareTo(Object o) {
        ResponseEntry other = (ResponseEntry) o;
        return sequence.compareTo(other.getSequence());
    }
}